namespace CQIE.TES.Model
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class MyDB : DbContext
    {
        public MyDB()
            : base("name=Model2")
        {
            //this.Configuration.LazyLoadingEnabled = false;
        }

        public virtual DbSet<Admin> Admin { get; set; }
        public virtual DbSet<Class_> Class_ { get; set; }
        public virtual DbSet<Class_Course> Class_Course { get; set; }
        public virtual DbSet<Course> Course { get; set; }
        public virtual DbSet<Department> Department { get; set; }
        public virtual DbSet<EvaluaHeight> EvaluaHeight { get; set; }
        public virtual DbSet<Question> Question { get; set; }
        public virtual DbSet<Record> Record { get; set; }
        public virtual DbSet<Role> Role { get; set; }
        public virtual DbSet<Student> Student { get; set; }
        public virtual DbSet<StudyYear> StudyYear { get; set; }
        public virtual DbSet<sysdiagrams> sysdiagrams { get; set; }
        public virtual DbSet<Teacher> Teacher { get; set; }
        public virtual DbSet<Teacher_Course> Teacher_Course { get; set; }
        public virtual DbSet<TeachingOffice> TeachingOffice { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Class_>()
                .HasMany(e => e.Class_Course)
                .WithOptional(e => e.Class_)
                .HasForeignKey(e => e.ClassID);

            modelBuilder.Entity<Class_>()
                .HasMany(e => e.Student)
                .WithOptional(e => e.Class_)
                .HasForeignKey(e => e.ClassID);

            modelBuilder.Entity<Department>()
                .HasMany(e => e.Teachers)
                .WithOptional(e => e.Department)
                .HasForeignKey(e => e.DepartmentID);

            modelBuilder.Entity<Question>()
                .HasMany(e => e.Children)
                .WithOptional(e => e.Parent)
                .HasForeignKey(e => e.ParentId);

            modelBuilder.Entity<Role>()
                .HasMany(e => e.Teacher)
                .WithOptional(e => e.Role1)
                .HasForeignKey(e => e.Role);

            modelBuilder.Entity<StudyYear>()
                .HasMany(e => e.Courses)
                .WithOptional(e => e.StudyYear)
                .HasForeignKey(e => e.StudyYearID);

            modelBuilder.Entity<StudyYear>()
                .HasMany(e => e.Evaluas)
                .WithOptional(e => e.StudyYear)
                .HasForeignKey(e => e.StudyYearId);

            modelBuilder.Entity<StudyYear>()
                .HasMany(e => e.Records)
                .WithOptional(e => e.StudyYear)
                .HasForeignKey(e => e.StudyYearID);

            modelBuilder.Entity<Teacher>()
                .HasMany(e => e.Record)
                .WithOptional(e => e.Teacher)
                .HasForeignKey(e => e.AimTeacher);

            modelBuilder.Entity<Teacher_Course>()
                .HasMany(e => e.TeachInfo)
                .WithOptional(e => e.CourseInfo)
                .HasForeignKey(e => e.ClassInfo);

            modelBuilder.Entity<EvaluaHeight>()
                .HasMany(e => e.Records)
                .WithOptional(e => e.Eva)
                .HasForeignKey(e => e.EvaId);

            modelBuilder.Entity<Course>()
                .HasMany(e => e.Records)
                .WithOptional(e => e.Course)
                .HasForeignKey(e => e.CourseID);

            modelBuilder.Entity<TeachingOffice>()
                .HasMany(e => e.Teachers)
                .WithOptional(e => e.TeachingOffice)
                .HasForeignKey(e => e.TeachingOfficeID);
        }
    }
}
